/*
 * UserNet  --  TCP/IP implementation in userspace
 * Copyright (C) 2010  Robert Millan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UNET_UNET_H
#define UNET_UNET_H 1

#include <stdint.h>
#include <netinet/in.h>		/* struct in_addr */

#include "unet/ip.h"

typedef struct
{
  enum ip_protocols protocol;
  struct in_addr addr;
  uint16_t port;
  void *state;
} *unet_listen_t;

typedef struct
{
  enum ip_protocols protocol;
  uint16_t src_port;
  void *state;
} *unet_connect_t;

extern int unet_init () __attribute__ ((warn_unused_result));
extern void unet_fini ();

extern unet_listen_t unet_listen (enum ip_protocols protocol, struct in_addr listen_addr, uint16_t port, int n);
extern void unet_listen_close (unet_listen_t this);

extern unet_connect_t unet_connect (enum ip_protocols protocol, struct in_addr dest_addr, uint16_t port);
extern unet_connect_t unet_accept (unet_listen_t this);
extern void unet_conn_close (unet_connect_t connection);

extern void unet_send (unet_connect_t connection, const void *buf, size_t n);
extern size_t unet_recv (unet_connect_t connection, void *buf, size_t n);

#endif
